package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.DocTaskSendDao;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.doc.DocSendWork;
import com.prs.crm.domain.doc.DocTaskSend;
import com.prs.crm.domain.doc.Document;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.doc.DocSendWorkService;
import com.prs.crm.service.doc.DocTaskSendService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.hr.ResumeService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class DocTaskSendServiceImpl extends
		BaseServiceImpl<DocTaskSend, DocTaskSendDao> implements
		DocTaskSendService {
	private PersonService personService;
	private ResumeService resumeService;
	private DocTaskSendService docTaskSendService;
	private DocSendWorkService docSendWorkService;
	



	public PersonService getPersonService() {
		return personService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public ResumeService getResumeService() {
		return resumeService;
	}

	public void setResumeService(ResumeService resumeService) {
		this.resumeService = resumeService;
	}

	@Override
	public Collection<Document> getDocTaskSendByIds(Integer[] ids) {

		return this.getDao().getDocTaskSendByIds(ids);
	}

	public DocTaskSendService getDocTaskSendService() {
		return docTaskSendService;
	}

	public void setDocTaskSendService(DocTaskSendService docTaskSendService) {
		this.docTaskSendService = docTaskSendService;
	}

	@Override
	public void submitDocTaskSend(Date wordStartTime, Date wordEndTime,
			String DocIds, String receivePersons, String[] docNames,
			String[] docCodes, String[] dockeyWords, Attachment[] attachs) {

		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
			for (Person person : persons) {
				DocTaskSend word = new DocTaskSend();
				word.setReceivePerson(person);
				word.setStartTime(wordStartTime);
				word.setEndTime(wordEndTime);           
				this.getDao().save(word);
				for(int i=0;i<docNames.length;i++ ){
					DocSendWork  dwOb=new DocSendWork();
					dwOb.setDocName(docNames[i]);
					dwOb.setDocCode(docCodes[i]);
					dwOb.setDockeyWord(dockeyWords[i]);
					dwOb.setAttach(attachs[i]);
					dwOb.setDocTaskSend(word);
				this.getDocSendWorkService().save(dwOb);
                }
			}
		
	}

	public DocSendWorkService getDocSendWorkService() {
		return docSendWorkService;
	}

	public void setDocSendWorkService(DocSendWorkService docSendWorkService) {
		this.docSendWorkService = docSendWorkService;
	}

}
